<?php
require_once("common.php");
$imageid = intval($_GET['id']);
if(!$imageid){ exit("非法ID");}
$sql = "SELECT * FROM ".tname('image')." WHERE id='$imageid' AND ifdelete=0";
$image = $db->get_one($sql);
!$image && exit("作品不存在");

include(S_ROOT."data/dataconfig.php");
if($_CONFIG['limitip']){ //是否限制IP
	$limitTime = 24*60*60;//一天

	/**
	 * 删除投票时间大于限制时间的记录
	 **/
	$db->query("DELETE FROM ".tname('vote')." WHERE ".time()."-votetime>$limitTime");

	$ip = getonlineip();
	$query = $db->query("SELECT * FROM ".tname('vote')." WHERE ip='$ip' AND imageid='$imageid'");
	$rs = $db->fetch_all($query);
	if(sizeof($rs)>0){
		exit("你已投过票，请勿重复投票！");
	}else{
		$db->query("INSERT  ".tname('vote')." SET ip='$ip',votetime='".time()."',imageid='$imageid'");
	}
}

$db->query("UPDATE  ".tname('image')." SET votenum=votenum+1 WHERE id='$imageid' AND ifdelete=0 ");
if($db->affected_rows()>0){
	echo "success";
}else{
	echo "投票失败！";
}


?>